#include "Tool/Toolkit.h"
#include "Base/PluginGenerator.h"
#include "MainUI/FrameUI.h"
#include "SystemUI.h"

GENERATE_PLUGIN(ISystemUI, SystemUI, SYSTEM_UI_PLUGIN)

// Construct the test ui
SystemUI::SystemUI():
	m_bDisposed(false)
{
	Initialize();
}

// Destruct the test ui
SystemUI::~SystemUI()
{
	Destory();
}

// Initialize the Test
void SystemUI::Initialize()
{
	// Create ui
	CreateMainUI();
}

// Destory the Test
void SystemUI::Destory()
{
	if (!GetDisposed())
	{
		SetDisposed(true);

		// Destroy ui
		DestoryMainUI();
	}
}

// Create main ui
void SystemUI::CreateMainUI()
{
    SetMainUI(new FrameUI);

	if (GetMainUI())
	{
		GetMainUI()->SetSystemUI(this);
	}
}

// Destroy main ui
void SystemUI::DestoryMainUI()
{
    if(GetMainUI())
    {
        delete GetMainUI();

        SetMainUI(NULL);
    }
}

// Start the plugin
bool SystemUI::Start()
{
	if (GetIsRunning())
	{
		return true;
	}

	SetIsRunning(true);

	if (GetMainUI() == NULL)
	{
		return false;
	}

	if (!GetMainUI()->Start())
	{
		return false;
	}

	MessageBoxA(NULL, "Start SystemUI", "SYS_MODULE", 0);

	qApp->exec();

	return true;
}

// Stop the plugin
bool SystemUI::Stop()
{
	if (GetIsRunning())
	{
		if (GetMainUI() == NULL)
		{
			return false;
		}

		if (!GetMainUI()->Stop())
		{
			return false;
		}

		SetIsRunning(false);

		MessageBoxA(NULL, "Stop SystemUI", "SYS_MODULE", 0);
	}

	return true;
}

// Show the UI
bool SystemUI::ShowUI()
{
	return true;
}
